import { addGlobalUncaughtErrorHandler, registerMicroApps, start } from 'qiankun'
// 子应用的信息
import apps from './app'

// 注册子应用
registerMicroApps(apps, {
  // 子应用加载前
  beforeLoad: app => {
    console.log('before load----', app.name + '\n')
    return Promise.resolve()
  },
  // 子应用加载后
  afterMount: app => {
    console.log('after mount----', app.name + '\n')
    return Promise.resolve()
  }
})

// 添加全局的未捕获异常处理器
addGlobalUncaughtErrorHandler(e => {
  const { message: msg } = e
  if (msg && msg.includes('died in status LOADING_SOURCE_CODE')) {
    console.error('---子应用加载失败----' + '\n')
  }
})

// 导出 qiankun 的启动函数
export default start
